use std::collections::HashMap;

use super::errors::Result;
use crate::structs::{FieldProps, OrderItems, WhereCauses};
use async_trait::async_trait;
use serde_json::Value;

#[async_trait]
pub trait DataAccessTrait: Send + Sync {
    async fn create_by_json(&self, map_val: serde_json::Value) -> Result<u64>;
    async fn update_by_json(&self, map_val: serde_json::Value) -> Result<u64>;
    async fn save_by_json(&self, map_val: serde_json::Value) -> Result<u64>;
    async fn delete_by_json(&self, map_val: serde_json::Value) -> Result<u64>;
    async fn delete_by_id(&self, id: u64) -> Result<u64>;
    async fn delete_by_ids(&self, ids: Vec<u64>) -> Result<u64>;
    async fn delete_by_map(&self, para_vals: &HashMap<String, String>) -> Result<u64>;
    async fn find_by_id(&self, id: u64) -> Result<Option<serde_json::Value>>;
    fn get_field_props(&self) -> Vec<FieldProps>;
    fn get_primary_key_name(&self) -> &'static str;
    async fn find_id_by_uniqe_keys(
        &self,
        para_vals: HashMap<String, String>,
    ) -> crate::base::Result<Option<u64>>;
    async fn find_json_by_uniqe_keys(
        &self,
        para_vals: HashMap<String, String>,
    ) -> crate::base::Result<Option<Value>>;
    async fn find_in_page(
        &self,
        where_causes: Option<WhereCauses>,
        orders: Option<OrderItems>,
        page: u64,
        page_size: u64,
    ) -> Result<(Vec<serde_json::Value>, u64)>;
}
